package com.szqhyxj.youxiangju.biz.login;

import com.szqhyxj.youxiangju.sys.BaseResult;
import com.szqhyxj.youxiangju.sys.RetrofitFacade;

import io.reactivex.Observable;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;

public class LoginModel {

    public interface LoginService {
        @FormUrlEncoded
        @POST("user/login")
        Observable<BaseResult<LoginResult>> login(
                @Field("useraccount") String user,
                @Field("loginPwd") String password,
                @Field("loginType") String loginType
        );

        @FormUrlEncoded
        @POST("user/updateAppAlias")
        Observable<BaseResult<Object>> updateAppAlias(
                @Field("alias") String alias
        );
    }

    public static Observable<BaseResult<LoginResult>> login(LoginEntity loginEntity) {
        return RetrofitFacade.Companion.getRetrofit().create(LoginService.class).login(
                loginEntity.getAccount(),
                loginEntity.getPassword(),
                loginEntity.getLoginType()
        );
    }


    public static Observable<BaseResult<Object>> updateAppAlias(String alias) {
        return RetrofitFacade.Companion.getRetrofit().create(LoginService.class).updateAppAlias(alias);
    }

    public static class LoginResult {
        private String token;

        public String getToken() {
            return token;
        }

        public void setToken(String token) {
            this.token = token;
        }

        public LoginResult(String token) {
            this.token = token;
        }
    }

    public static class LoginEntity {

        private String password;

        private String account;

        private String loginType = "1";

        public LoginEntity(String password, String account) {
            this.password = password;
            this.account = account;
        }

        public LoginEntity() {
        }

        public String getPassword() {
            return password;
        }

        public void setPassword(String password) {
            this.password = password;
        }

        public String getAccount() {
            return account;
        }

        public void setAccount(String account) {
            this.account = account;
        }

        public String getLoginType() {
            return loginType;
        }

    }
}